<?php
namespace App\Admin\Logic\Ty;

use App\Admin\Logic\BaseLogic;
use App\Models\SwtBjMachine;
use App\Services\TuoYuanService;

class TyMachineLogic extends BaseLogic
{
    public static function asyncMachine($params) {
        $res = TuoYuanService::getDeviceInfo($params);

        switch ($res['data']['status'])
        {
            case 2000:
                $update = ['is_register' => 1];
                break;
            case 3000:
                $update = ['is_register' => 3];
            break;
            case 4000:
                $update = ['is_register' => 2];
            break;
            case 5000:
                $update = ['is_register' => 4];
            break;
            default:
                $res = TuoYuanService::setDeviceInfo($params);
                if($res['data']['acceptanceResult'] == 0) {
                    $update = ['is_register' => 1];
                } else {
                    self::$error = $res['data']['message'];
                    return false;
                }
            break;
        }
        SwtBjMachine::where('id', $params['id']) -> update($update);
        return true;
    }
}
